<template>
  <div class="app-container">
    <el-row>
      <el-col v-for="(item, index) in form.cpyMenuList" :key="index" :span="6">
        <el-card class="card">
          <div :class="item.menuStatus">
            <el-checkbox v-if="item.menuLevel == 'private'" v-model="item.checked" />
            <span>{{ item.menuRangeDesc }}</span>
          </div>
          <div class="bottom cleafix">
            {{ item.menuRmk }}
          </div>
        </el-card>
      </el-col>
    </el-row>
    <div v-permission="['SYS_ADMIN','COMMON_ADMIN']" slot="footer" class="dialog-footer" style="padding: 50px">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </div>
</template>

<script>
import { doApplyMenu, getAllValidMenu } from '@/api/system/cpy'
import { getUserInfo } from '@/utils/auth'

export default {
  components: { },
  props: {
  },
  data() {
    return {
      isAdd: false,
      loading: false,
      dialog: false,
      style: 'width: 184px',
      form: {
        busMainData: {
        },
        cpyMenuList: []
      }
    }
  },
  mounted() {
    this.viewMainData()
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    initDataOfBefore() {
    },
    viewMainData() {
      const userInfo = getUserInfo()
      const cpycode = userInfo.cpyCode
      getAllValidMenu(cpycode).then(res => {
        this.form.cpyMenuList = res.data
      })
    },
    doSubmit() {
      doApplyMenu(this.form).then(res => {
        this.loading = false
        this.viewMainData()
      }).catch(err => {
        this.loading = false
        console.log(err)
      })
    },
    resetForm() {
      this.dialog = false
    }
  }
}
</script>

<style>
  .card {
    background-color: rgba(156, 91, 255, 0.02);
    margin: 10px;
  }
  .valid {
    background-color: rgba(66, 147, 241, 0.04);
    font-size: 18px;
  }
  .wait {
    background-color: rgba(222, 37, 101, 0.08);
  }
  .bottom {
    margin: 10px;
    color: #d9d9d9;
  }
</style>
